package com.op.teachingliteapp.sender.ui.view.device;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.op.teachingliteapp.R;

import java.util.List;

/**
 * Created by Genji on 2015/7/7.
 */
public class DeviceDisplayAdapter extends ArrayAdapter<DeviceDisplay> {
    private int resourceId;
    private List<DeviceDisplay> deviceDisplayList;
    private LayoutInflater inflater;


    public DeviceDisplayAdapter(Context context, int textViewResourceId, List<DeviceDisplay> objects) {
        super(context, textViewResourceId, objects);
        this.resourceId = textViewResourceId;
        this.deviceDisplayList = objects;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView;
        if (convertView == null) {
            convertView = inflater.inflate(resourceId, null);
            textView = (TextView) convertView.findViewById(R.id.device_info);


            convertView.setTag(textView);
        } else {
             textView = (TextView) convertView.getTag();
        }
        String deviceInfo = deviceDisplayList.get(position).toString();
        textView.setText(deviceInfo);


        return convertView;
    }

}
